package com.accp.ssmoa.pojo;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

//树形菜单封装类（针对组织结构表）
public class DepartmentTree {

	    public static Map<String,Object> mapArray = new LinkedHashMap<String, Object>();  
	       public List<Department> departmentCommon;  
	       List<Object> list= new ArrayList<Object>();  
	       
	       //根节点
	       public List<Object> departmentList(List<Department> departments){      
	           this.departmentCommon = departments;  
	           for (Department department : departments) {     
	               Map<String,Object> mapArr = new LinkedHashMap<String, Object>();  
	               if(department.getParentdepartmentid()==0){  
	                   mapArr.put("id", department.getId());  
	                   mapArr.put("name", department.getName());  
	                   mapArr.put("pid", department.getParentdepartmentid());    
	                   mapArr.put("child", departmentChild(department.getId()));    
	                   list.add(mapArr); 
	               }  
	           }     
	           return list;  
	       }  
	         
	       //子节点  
	       public List<Object> departmentChild(int id){  
	           List<Object> lists = new ArrayList<Object>();  
	           for(Department department:departmentCommon){  
	               Map<String,Object> childArray = new LinkedHashMap<String, Object>();  
	               if(department.getParentdepartmentid() == id){  
	                   childArray.put("id", department.getId());  
	                   childArray.put("name", department.getName());  
	                   childArray.put("pid", department.getParentdepartmentid());  
	                   childArray.put("child", departmentChild(department.getId()));    
	                   lists.add(childArray);  
	               }  
	           }  
	           return lists;  
	            
	       }  
}
